package com.bafa.front.presentationbeans;

import java.util.Date;
import java.util.HashMap;

import com.bafa.objects.Match;
import com.bafa.services.RetrieveServices;
import com.bafa.util.WebsiteUtils;

public class TeamMatchBean implements Comparable {

	private int ID;
    protected Date date;
    private int teamA;
    private int oppositionId;
    private String teamAName;
    private String oppositionName;
    private int ourGoals;
    private int oppositionGoals;
    protected boolean blocked;
    protected boolean played;
    protected boolean walkover;
    protected String time;
    protected boolean confirmed;
    private boolean resultAdded;
    private boolean oppositionAdded;
    private PlayerListBean scorers;
	private boolean won;
	private boolean drawn;
	public boolean isDrawn() {
		return drawn;
	}

	public void setDrawn(boolean drawn) {
		this.drawn = drawn;
	}

	public boolean isWon() {
		return won;
	}

	public void setWon(boolean won) {
		this.won = won;
	}

	public TeamMatchBean(Match match, int teamId) {
		boolean home = (match.getTeamA()==teamId);
		this.date = match.getDate();
		this.ID = match.getID();
		
		this.oppositionId = (home)?match.getTeamB():match.getTeamA();
		this.oppositionName = RetrieveServices.getTeam(oppositionId+"").getName();
		this.blocked = match.isBlocked();
		this.played = match.isPlayed();
		this.walkover = match.isWalkover();
		this.confirmed = match.isConfirmed();
		this.resultAdded = (home)?match.isHomeAdded():match.isAwayAdded();
		this.oppositionAdded = (home)?match.isAwayAdded():match.isHomeAdded();
		this.ourGoals = (home)?match.getGoalsA():match.getGoalsB();
		this.oppositionGoals = (home)?match.getGoalsB():match.getGoalsA();
		if(ourGoals>oppositionGoals)
			won = true;
		if(ourGoals==oppositionGoals)
			drawn = true;
		this.time = match.getTime();
		
		scorers = new PlayerListBean((home)?match.scorersA():match.scorersB(),match);
	}
	
	public boolean isOppositionAdded() {
		return oppositionAdded;
	}



	public void setOppositionAdded(boolean awayAdded) {
		this.oppositionAdded = awayAdded;
	}



	public boolean isBlocked() {
		return blocked;
	}



	public void setBlocked(boolean blocked) {
		this.blocked = blocked;
	}



	public boolean isConfirmed() {
		return confirmed;
	}



	public void setConfirmed(boolean confirmed) {
		this.confirmed = confirmed;
	}



	public Date getDate() {
		return date;
	}



	public void setDate(Date date) {
		this.date = date;
	}



	public int getOurGoals() {
		return ourGoals;
	}



	public void setOurGoals(int goalsA) {
		this.ourGoals = goalsA;
	}



	public int getOppositionGoals() {
		return oppositionGoals;
	}



	public void setOppositionGoals(int goalsB) {
		this.oppositionGoals = goalsB;
	}



	public boolean isResultAdded() {
		return resultAdded;
	}



	public void setResultAdded(boolean homeAdded) {
		this.resultAdded = homeAdded;
	}



	public int getID() {
		return ID;
	}



	public void setID(int id) {
		ID = id;
	}



	public boolean isPlayed() {
		return played;
	}



	public void setPlayed(boolean played) {
		this.played = played;
	}



	






	public int getTeamA() {
		return teamA;
	}



	public void setTeamA(int teamA) {
		this.teamA = teamA;
	}



	public String getTeamAName() {
		return teamAName;
	}



	public void setTeamAName(String teamAName) {
		this.teamAName = teamAName;
	}



	public int getOppositionId() {
		return oppositionId;
	}



	public void setOppositionId(int teamB) {
		this.oppositionId = teamB;
	}



	public String getOppositionName() {
		return oppositionName;
	}



	public void setOppositionName(String teamBName) {
		this.oppositionName = teamBName;
	}



	public String getTime() {
		return time;
	}



	public void setTime(String time) {
		this.time = time;
	}



	public boolean isWalkover() {
		return walkover;
	}



	public void setWalkover(boolean walkover) {
		this.walkover = walkover;
	}



	public int compareTo(Object arg0) {
		TeamMatchBean bean = (TeamMatchBean)arg0;
		
		if(!bean.getDate().equals(this.date)){
			return this.getDate().compareTo(bean.getDate());
		}else if(bean.getTime()!=null&&this.time!=null&&!bean.getTime().equals(this.time)){
			return this.getTime().compareTo(bean.getTime());
		}else{
			return bean.getID()- this.getID();
		}
	}
	
	public int day(){
        return date.getDate();
}

public String dayOfWeek(){
        return WebsiteUtils.getDayOfWeek(date.getDay());
}

public String month(){
        return WebsiteUtils.getMonth(date.getMonth());
}

public int year(){
        return date.getYear()+1900;
}

public String getDateOfMatch(){
        if(date==null) return "";
        return dayOfWeek()+" "+day()+" "+month()+" "+year();
}

public boolean isResultDue(){
        Date today = new Date();
        if(date!=null&&date.before(today)){
                return !resultAdded&&!isBlocked();
        }else{
                return false;
        }
        
}

public PlayerListBean getScorers() {
	return scorers;
}

public void setScorers(PlayerListBean players) {
	this.scorers = players;
}

}
